package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.excel.ExcelUtil;
import com.gfxy.modules.items.entity.Bzsc;
import com.gfxy.modules.items.mapper.BzscMapper;
import com.gfxy.modules.items.service.IBzscService;
import com.gfxy.modules.items.vo.BzscMemberPage;
import com.gfxy.modules.items.vo.ZyyxsztsjhMemberPage;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 标准输出
 * @Author: jeecg-boot
 * @Date:   2023-12-19
 * @Version: V1.0
 */
@Service
public class BzscServiceImpl extends AbstractProjectServiceImpl<BzscMapper, Bzsc> implements IBzscService {


	public BzscServiceImpl() {
		this.memberCellNum = 3;
	}

	@Override
	public IPage<BzscMemberPage> selectListPage(String date, Integer pageNo, Integer pageSize) {

		Page<BzscMemberPage> page = new Page<>(pageNo, pageSize);

		Page<BzscMemberPage> page1 = page.setRecords(baseMapper.selectMemberPageListByYear(date));

		return page1;
	}

	@Override
	public List<BzscMemberPage> getMemberPageListByYear(String date) {
		return baseMapper.selectMemberPageListByYear(date);
	}


	/**
	 * 计算总分
	 * @param bzsc
	 * @return
	 */
	@Override
	public Double getTotalScore(Bzsc bzsc) {

		Integer classess = bzsc.getClassess();
		double result = 0;
		if(classess == 1){
			result = 150;
		} else if(classess == 2){
			result = 100;
		}
		return result;
	}

	@Override
	protected Bzsc getOneProject(Row row) {
		String date =  ExcelUtil.formatCell(row.getCell(0));
		String classessStr =  ExcelUtil.formatCell(row.getCell(1));
		String name =  ExcelUtil.formatCell(row.getCell(2));

		Bzsc bzsc = new Bzsc();
		bzsc.setDate(date);
		bzsc.setClassess(this.translateClassess(classessStr));
		bzsc.setProjectName(name);

		bzsc.setTotalScore(this.getTotalScore(bzsc));
		return bzsc;
	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	private Integer translateClassess(String levelStr) {
		if(levelStr == null || levelStr.equals("")){
			return 0;
		} else if(levelStr.equals("获国（境）外教育主管部门认证")){
			return 1;
		} else if(levelStr.equals("获国（境）外大学认证")){
			return 2;
		}else {
			return 0;
		}
	}

}
